﻿using System;
using System.Collections.Generic;
using System.Text;
using NHibernate;
using NHibernate.Expression;
using Castle.ActiveRecord;
using Castle.Components.Validator;
using System.ComponentModel;
using Castle.ActiveRecord.Queries;
using Mang24k99.Model.COMM;

namespace Mang24k99.Model.PUBC
{
    [ActiveRecord(Table = "KT_PUBC_CYC")]
    public partial class MKtPubcCyc : ActiveRecordBase
    {
        /// <summary>
        /// Deleteses the specified where.
        /// </summary>
        /// <param name="where">The where.</param>
        public static void Deletes(string where)
        {
            DeleteAll(typeof(MKtPubcCyc), where);
        }
        /// <summary>
        /// Deleteses the specified pk values.
        /// </summary>
        /// <param name="pkValues">The pk values.</param>
        public static void Deletes(System.Collections.IEnumerable pkValues)
        {
            DeleteAll(typeof(MKtPubcCyc), pkValues);
        }

        /// <summary>
        /// Selects all.
        /// </summary>
        /// <returns></returns>
        public static IList<MKtPubcCyc> SelectAll()
        {
            return (IList<MKtPubcCyc>)FindAll(typeof(MKtPubcCyc));
        }
        /// <summary>
        /// Selects all.
        /// </summary>
        /// <param name="criteria">The criteria.</param>
        /// <returns></returns>
        public static IList<MKtPubcCyc> SelectAll(params ICriterion[] criteria)
        {
            return (IList<MKtPubcCyc>)FindAll(typeof(MKtPubcCyc), criteria);
        }
        /// <summary>
        /// Selects all.
        /// </summary>
        /// <param name="orders">The orders.</param>
        /// <param name="criteria">The criteria.</param>
        /// <returns></returns>
        public static IList<MKtPubcCyc> SelectAll(Order[] orders, params ICriterion[] criteria)
        {
            return (IList<MKtPubcCyc>)FindAll(typeof(MKtPubcCyc), orders, criteria);
        }
        /// <summary>
        /// Selects all.
        /// </summary>
        /// <param name="detachedCriteria">The detached criteria.</param>
        /// <param name="orders">The orders.</param>
        /// <returns></returns>
        public static IList<MKtPubcCyc> SelectAll(DetachedCriteria detachedCriteria, params Order[] orders)
        {
            return (IList<MKtPubcCyc>)FindAll(typeof(MKtPubcCyc), detachedCriteria, orders);
        }


        /// <summary>
        /// Selects all query.
        /// </summary>
        /// <param name="query">The query.</param>
        /// <returns></returns>
        [DataObjectMethod(DataObjectMethodType.Select)]
        public static IList<MKtPubcCyc> SelectAllQuery(SimpleQuery query)
        {
            return (IList<MKtPubcCyc>)ExecuteQuery(query);
        }


        /// <summary>
        /// Selects the by primary key.
        /// </summary>
        /// <param name="ID">The ID.</param>
        /// <returns></returns>
        public static MKtPubcCyc SelectByPrimaryKey(object ID)
        {
            return (MKtPubcCyc)FindByPrimaryKey(typeof(MKtPubcCyc), ID, false);
        }

        /// <summary>
        /// Selects the by primary key.
        /// </summary>
        /// <param name="ID">The ID.</param>
        /// <returns></returns>
        public static MKtPubcCyc SelectOne(DetachedCriteria detachedCriteria)
        {
            return (MKtPubcCyc)FindOne(typeof(MKtPubcCyc), detachedCriteria);
        }
        /// <summary>
        /// Selects the one.
        /// </summary>
        /// <param name="criteria">The criteria.</param>
        /// <returns></returns>
        public static MKtPubcCyc SelectOne(params ICriterion[] criteria)
        {
            return (MKtPubcCyc)FindOne(typeof(MKtPubcCyc), criteria);
        }

        /// <summary>
        /// Selects the first.
        /// </summary>
        /// <param name="criteria">The criteria.</param>
        /// <returns></returns>
        public static MKtPubcCyc SelectFirst(params ICriterion[] criteria)
        {
            return (MKtPubcCyc)FindFirst(typeof(MKtPubcCyc), criteria);
        }
        /// <summary>
        /// Selects the first.
        /// </summary>
        /// <param name="orders">The orders.</param>
        /// <param name="criteria">The criteria.</param>
        /// <returns></returns>
        public static MKtPubcCyc SelectFirst(Order[] orders, params ICriterion[] criteria)
        {
            return (MKtPubcCyc)FindFirst(typeof(MKtPubcCyc), orders, criteria);
        }
        /// <summary>
        /// Selects the first.
        /// </summary>
        /// <param name="detachedCriteria">The detached criteria.</param>
        /// <param name="orders">The orders.</param>
        /// <returns></returns>
        public static MKtPubcCyc SelectFirst(DetachedCriteria detachedCriteria, Order[] orders)
        {
            return (MKtPubcCyc)FindFirst(typeof(MKtPubcCyc), detachedCriteria, orders);

        }

        /// <summary>
        /// Selects the ALL by property.
        /// </summary>
        /// <param name="property">The property.</param>
        /// <param name="value">The value.</param>
        /// <returns></returns>
        public static IList<MKtPubcCyc> SelectALLByProperty(string property, object value)
        {
            return (IList<MKtPubcCyc>)FindAllByProperty(typeof(MKtPubcCyc), property, value);
        }
        /// <summary>
        /// Selects the ALL by property.
        /// </summary>
        /// <param name="orderByColumn">The order by column.</param>
        /// <param name="property">The property.</param>
        /// <param name="value">The value.</param>
        /// <returns></returns>
        public static IList<MKtPubcCyc> SelectALLByProperty(string orderByColumn, string property, object value)
        {
            return (IList<MKtPubcCyc>)FindAllByProperty(typeof(MKtPubcCyc), orderByColumn, property, value);
        }

        /// <summary>
        /// Selects the ALL sliced.
        /// </summary>
        /// <param name="firstResult">The first result.</param>
        /// <param name="maxResult">The max result.</param>
        /// <param name="detachedCriteria">The detached criteria.</param>
        /// <returns></returns>
        public static IList<MKtPubcCyc> SelectALLSliced(int firstResult, int maxResult, DetachedCriteria detachedCriteria)
        {
            return (IList<MKtPubcCyc>)SlicedFindAll(typeof(MKtPubcCyc), firstResult, maxResult, detachedCriteria);
        }
        /// <summary>
        /// Selects the ALL sliced.
        /// </summary>
        /// <param name="firstResult">The first result.</param>
        /// <param name="maxResult">The max result.</param>
        /// <param name="criteria">The criteria.</param>
        /// <returns></returns>
        public static IList<MKtPubcCyc> SelectALLSliced(int firstResult, int maxResult, params ICriterion[] criteria)
        {
            return (IList<MKtPubcCyc>)SlicedFindAll(typeof(MKtPubcCyc), firstResult, maxResult, criteria);
        }
        /// <summary>
        /// Selects the ALL sliced.
        /// </summary>
        /// <param name="firstResult">The first result.</param>
        /// <param name="maxResult">The max result.</param>
        /// <param name="orders">The orders.</param>
        /// <param name="detachedCriteria">The detached criteria.</param>
        /// <returns></returns>
        public static IList<MKtPubcCyc> SelectALLSliced(int firstResult, int maxResult, Order[] orders, DetachedCriteria detachedCriteria)
        {
            return (IList<MKtPubcCyc>)SlicedFindAll(typeof(MKtPubcCyc), firstResult, maxResult, orders, detachedCriteria);
        }
        /// <summary>
        /// Selects the ALL sliced.
        /// </summary>
        /// <param name="firstResult">The first result.</param>
        /// <param name="maxResult">The max result.</param>
        /// <param name="orders">The orders.</param>
        /// <param name="criteria">The criteria.</param>
        /// <returns></returns>
        public static IList<MKtPubcCyc> SelectALLSliced(int firstResult, int maxResult, Order[] orders, params ICriterion[] criteria)
        {
            return (IList<MKtPubcCyc>)SlicedFindAll(typeof(MKtPubcCyc), firstResult, maxResult, orders, criteria);
        }

        /// <summary>
        /// Countses this instance.
        /// </summary>
        /// <returns></returns>
        public static int Counts()
        {
            return Count(typeof(MKtPubcCyc));
        }
        /// <summary>
        /// Countses the specified detached criteria.
        /// </summary>
        /// <param name="detachedCriteria">The detached criteria.</param>
        /// <returns></returns>
        public static int Counts(DetachedCriteria detachedCriteria)
        {
            return Count(typeof(MKtPubcCyc), detachedCriteria);
        }
        /// <summary>
        /// Countses the specified criteria.
        /// </summary>
        /// <param name="criteria">The criteria.</param>
        /// <returns></returns>
        public static int Counts(params ICriterion[] criteria)
        {
            return Count(typeof(MKtPubcCyc), criteria);
        }


        /// <summary>
        /// Exists the specified id.
        /// </summary>
        /// <param name="id">The id.</param>
        /// <returns></returns>
        public static bool Exist(object id)
        {
            return Exists(typeof(MKtPubcCyc), id);
        }
        /// <summary>
        /// Exists the specified id.
        /// </summary>
        /// <param name="id">The id.</param>
        /// <param name="detachedCriteria">The detached criteria.</param>
        /// <returns></returns>
        public static bool Exist(DetachedCriteria detachedCriteria)
        {
            return Exists(typeof(MKtPubcCyc), detachedCriteria);
        }
        /// <summary>
        /// Exists the specified id.
        /// </summary>
        /// <param name="id">The id.</param>
        /// <param name="criteria">The criteria.</param>
        /// <returns></returns>
        public static bool Exist(params ICriterion[] criteria)
        {
            return Exists(typeof(MKtPubcCyc), criteria);
        }
        protected override void OnDelete()
        {
            DeleteTime = DateTime.Now;
            MKtPubcCycHistory mHistory = new MKtPubcCycHistory();
            Common.ModelCommon.CopyObjectValues(this, mHistory);
            mHistory.BoardNO = MKtPubcProduct.BoardNO;
            mHistory.CycType = MKtCommCodelist.CODE_NO;
            mHistory.Create();
            base.OnDelete();
        }
        /// <summary>
        /// 返回最大的调查表周期编号
        /// </summary>
        /// <returns></returns>
        public static int GetMaxCycNO()
        {
            MKtPubcCyc cyc = new MKtPubcCyc();
            string Hql = @"select max(cyc.CycNO) from MKtPubcCyc cyc  ";
            string count = @"select count(cyc.CycNO) from MKtPubcCyc cyc ";
            ScalarQuery querycount = new ScalarQuery(typeof(MKtPubcCyc), count);
            if (Convert.ToInt32(ExecuteQuery(querycount)) == 0)
            {
                return 0;
            }
            ScalarQuery query = new ScalarQuery(typeof(MKtPubcCyc), Hql);
            return (int)ExecuteQuery(query);
        }
        /// <summary>
        /// 通过where语句查询记录
        /// </summary>
        /// <param name="where"></param>
        /// <returns></returns>
        public static IList<MKtPubcCyc> SelectByWhere(string where)
        {
            string hql = "from MKtPubcCyc cyc "+where;
            SimpleQuery query = new SimpleQuery(typeof(MKtPubcCyc),hql);
            return (IList<MKtPubcCyc> )ExecuteQuery(query);
        }

        [BelongsTo("BOARD_NO", Cascade = CascadeEnum.None)]
        public MKtPubcProduct MKtPubcProduct
        {
            get
            {
                return _MKtPubcProduct;
            }
            set
            {
                _MKtPubcProduct = value;
            }
        }
        [BelongsTo("CYC_TYPE", Cascade = CascadeEnum.None)]
        public MKtCommCodeList MKtCommCodelist
        {
            get
            {
                return _MKtCommCodelist;
            }
            set
            {
                _MKtCommCodelist = value;
            }

        }
        

        [HasMany(typeof(MKtPubcItems), ColumnKey = "CYC_NO", Cascade = ManyRelationCascadeEnum.AllDeleteOrphan, Inverse = true, Lazy = true)]
        public IList<MKtPubcItems> MKtPubcItems
        {
            get
            {
                return _MKtPubcItems;
            }
            set
            {
                _MKtPubcItems = value;
            }
        }
        [HasMany(typeof(MKtPubcVote), ColumnKey = "CYC_NO", Cascade = ManyRelationCascadeEnum.AllDeleteOrphan, Inverse = true, Lazy = true)]
        public IList<MKtPubcVote> MKtPubcVote
        {
            get
            {
                return _MKtPubcVote;
            }
            set
            {
                _MKtPubcVote = value;
            }
        }
        [HasMany(typeof(MKtPubcVotelimit), ColumnKey = "CYC_NO", Cascade = ManyRelationCascadeEnum.AllDeleteOrphan, Inverse = true, Lazy = true)]
        public IList<MKtPubcVotelimit> MKtPubcVotelimit
        {
            get
            {
                return _MKtPubcVotelimit;
            }
            set
            {
                _MKtPubcVotelimit = value;
            }
        }

        /// <summary>
        /// Gets or sets the CycNO.(CycNO)
        /// </summary>
        /// <value>The CycNO.</value>
        /// <remarks>
        /// CycNO
        /// </remarks>
        [PrimaryKey(PrimaryKeyType.Assigned, "CYC_NO"),
        ValidateNonEmpty("CycNO不能为空"),
        ValidateRange(0, 2147483647, "CycNO的值要在0到2147483647之间"),
        ]
        public int? CycNO
        {
            get
            {
                return _CycNO;
            }
            set
            {
                _CycNO = value;
            }
        }


        /// <summary>
        /// Gets or sets the ID.(ID)
        /// </summary>
        /// <value>The ID.</value>
        /// <remarks>
        /// ID
        /// </remarks>
        [Property("ID", Insert = false, Update = false),
        ValidateNonEmpty("ID不能为空"),
        ValidateRange(0, 2147483647, "ID的值要在0到2147483647之间"),
        ]
        public int? ID
        {
            get
            {
                return _ID;
            }
            set
            {
                _ID = value;
            }
        }


        /// <summary>
        /// Gets or sets the CycName.(CycName)
        /// </summary>
        /// <value>The CycName.</value>
        /// <remarks>
        /// CycName
        /// </remarks>
        [Property("CYC_NAME"),
        ValidateLength(1, 120, "CycName长度必须在1到120之间"),
        ]
        public string CycName
        {
            get
            {
                return _CycName;
            }
            set
            {
                _CycName = value;
            }
        }


        /// <summary>
        /// Gets or sets the CycAlias.(CycAlias)
        /// </summary>
        /// <value>The CycAlias.</value>
        /// <remarks>
        /// CycAlias
        /// </remarks>
        [Property("CYC_ALIAS"),
        ValidateLength(1, 30, "CycAlias长度必须在1到30之间"),
        ]
        public string CycAlias
        {
            get
            {
                return _CycAlias;
            }
            set
            {
                _CycAlias = value;
            }
        }


        /// <summary>
        /// Gets or sets the TargetNum.(TargetNum)
        /// </summary>
        /// <value>The TargetNum.</value>
        /// <remarks>
        /// TargetNum
        /// </remarks>
        [Property("TARGET_NUM"),
        ValidateRange(0, 2147483647, "TargetNum的值要在0到2147483647之间"),
        ]
        public int? TargetNum
        {
            get
            {
                return _TargetNum;
            }
            set
            {
                _TargetNum = value;
            }
        }


        /// <summary>
        /// Gets or sets the LimitType.(LimitType)
        /// </summary>
        /// <value>The LimitType.</value>
        /// <remarks>
        /// LimitType
        /// </remarks>
        [Property("LIMIT_TYPE"),
        ValidateRange(0, 2147483647, "LimitType的值要在0到2147483647之间"),
        ]
        public int? LimitType
        {
            get
            {
                return _LimitType;
            }
            set
            {
                _LimitType = value;
            }
        }


        /// <summary>
        /// Gets or sets the SucessMsg.(SucessMsg)
        /// </summary>
        /// <value>The SucessMsg.</value>
        /// <remarks>
        /// SucessMsg
        /// </remarks>
        [Property("SUCESS_MSG"),
        ValidateLength(1, 120, "SucessMsg长度必须在1到120之间"),
        ]
        public string SucessMsg
        {
            get
            {
                return _SucessMsg;
            }
            set
            {
                _SucessMsg = value;
            }
        }


        /// <summary>
        /// Gets or sets the OvernumMsg.(OvernumMsg)
        /// </summary>
        /// <value>The OvernumMsg.</value>
        /// <remarks>
        /// OvernumMsg
        /// </remarks>
        [Property("OVERNUM_MSG"),
        ValidateLength(1, 120, "OvernumMsg长度必须在1到120之间"),
        ]
        public string OvernumMsg
        {
            get
            {
                return _OvernumMsg;
            }
            set
            {
                _OvernumMsg = value;
            }
        }


        /// <summary>
        /// Gets or sets the FailureMsg.(FailureMsg)
        /// </summary>
        /// <value>The FailureMsg.</value>
        /// <remarks>
        /// FailureMsg
        /// </remarks>
        [Property("FAILURE_MSG"),
        ValidateLength(1, 120, "FailureMsg长度必须在1到120之间"),
        ]
        public string FailureMsg
        {
            get
            {
                return _FailureMsg;
            }
            set
            {
                _FailureMsg = value;
            }
        }


        /// <summary>
        /// Gets or sets the CycUpdaterule.(CycUpdaterule)
        /// </summary>
        /// <value>The CycUpdaterule.</value>
        /// <remarks>
        /// CycUpdaterule
        /// </remarks>
        [Property("CYC_UPDATERULE"),
        ValidateLength(1, 120, "CycUpdaterule长度必须在1到120之间"),
        ]
        public string CycUpdaterule
        {
            get
            {
                return _CycUpdaterule;
            }
            set
            {
                _CycUpdaterule = value;
            }
        }


        /// <summary>
        /// Gets or sets the IsValidate.(IsValidate)
        /// </summary>
        /// <value>The IsValidate.</value>
        /// <remarks>
        /// IsValidate
        /// </remarks>
        [Property("IS_VALIDATE"),
        ValidateRange(0, 2147483647, "IsValidate的值要在0到2147483647之间"),
        ]
        public int? IsValidate
        {
            get
            {
                return _IsValidate;
            }
            set
            {
                _IsValidate = value;
            }
        }


        /// <summary>
        /// Gets or sets the InputTime.(InputTime)
        /// </summary>
        /// <value>The InputTime.</value>
        /// <remarks>
        /// InputTime
        /// </remarks>
        [Property("INPUT_TIME"),
        ]
        public DateTime? InputTime
        {
            get
            {
                return _InputTime;
            }
            set
            {
                _InputTime = value;
            }
        }


        /// <summary>
        /// Gets or sets the ModifyTime.(ModifyTime)
        /// </summary>
        /// <value>The ModifyTime.</value>
        /// <remarks>
        /// ModifyTime
        /// </remarks>
        [Property("MODIFY_TIME"),
        ]
        public DateTime? ModifyTime
        {
            get
            {
                return _ModifyTime;
            }
            set
            {
                _ModifyTime = value;
            }
        }


        /// <summary>
        /// Gets or sets the DeleteTime.(DeleteTime)
        /// </summary>
        /// <value>The DeleteTime.</value>
        /// <remarks>
        /// DeleteTime
        /// </remarks>
        [Property("DELETE_TIME"),
        ]
        public DateTime? DeleteTime
        {
            get
            {
                return _DeleteTime;
            }
            set
            {
                _DeleteTime = value;
            }
        }


        /// <summary>
        /// Gets or sets the LimitNum.(LimitNum)
        /// </summary>
        /// <value>The LimitNum.</value>
        /// <remarks>
        /// LimitNum
        /// </remarks>
        [Property("LIMIT_NUM"),
        ValidateRange(0, 2147483647, "LimitNum的值要在0到2147483647之间"),
        ]
        public int? LimitNum
        {
            get
            {
                return _LimitNum;
            }
            set
            {
                _LimitNum = value;
            }
        }



        private int? _CycNO;

        private IList<MKtPubcItems> _MKtPubcItems;
        private IList<MKtPubcVote> _MKtPubcVote;
        private IList<MKtPubcVotelimit> _MKtPubcVotelimit;
        private int? _ID;

        private MKtPubcProduct _MKtPubcProduct;
        private string _CycName;

        private string _CycAlias;

        private int? _TargetNum;

        private MKtCommCodeList _MKtCommCodelist;
        private int? _LimitType;

        private string _SucessMsg;

        private string _OvernumMsg;

        private string _FailureMsg;

        private string _CycUpdaterule;

        private int? _IsValidate;

        private DateTime? _InputTime;

        private DateTime? _ModifyTime;

        private DateTime? _DeleteTime;

        private int? _LimitNum;


    }
}
